fix : Add Groups filter to CustomResourceDefinition reconciler#937
fix : Add Groups filter to CustomResourceDefinition reconciler#937SatabdiG wants to merge 1 commit intocrossplane:mainfrom
Conversation
- Introduced Groups field in Options to specify API groups for CRDs. - Implemented GroupPredicate to filter CRDs based on specified groups. - Updated Setup function to apply the Groups filter during reconciliation. Signed-off-by: SatabdiG <satabdi.ganguly89@gmail.com>
📝 WalkthroughWalkthroughAdds an exported Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/reconciler/customresourcesgate/reconciler_test.go (1)
567-647: Good test coverage forGroupPredicate— one question about event type coverage.Thanks for the comprehensive test cases! The table-driven structure follows Crossplane conventions nicely, and the test cases cover the key scenarios well:
- ✅ CRD group present in filter
- ✅ CRD group absent from filter
- ✅ Empty groups list
- ✅ Non-CRD object handling
One curiosity: I noticed the test only exercises
got.Generic(ev). Sincepredicate.NewPredicateFuncsapplies the same function to all event types (Create, Update, Delete, Generic), this should be fine in practice. However, would you consider adding at least one test case that exercisesCreateorUpdateevents to document that the predicate is applied consistently across event types? This could help future maintainers understand that the filtering applies to all watch events.Totally optional — what are your thoughts?
💡 Example of testing Create event (optional)
"CRDGroupPresentCreateEvent": { reason: "CRD is present in the specified groups for Create event", args: args{ groups: []string{"example.com"}, obj: &apiextensionsv1.CustomResourceDefinition{ Spec: apiextensionsv1.CustomResourceDefinitionSpec{ Group: "example.com", }, }, }, want: want{ match: true, }, },Then in the test loop, you could add:
createEv := event.CreateEvent{Object: tc.args.obj} if got.Create(createEv) != tc.want.match { // ... }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/reconciler/customresourcesgate/reconciler_test.go` around lines 567 - 647, Add an extra assertion in TestGroupPredicate to exercise at least one non-Generic event (e.g., Create or Update) so the predicate behavior across event types is documented; locate the GroupPredicate(...) call and the existing ev := event.GenericEvent{Object: tc.args.obj} and add a corresponding createEv := event.CreateEvent{Object: tc.args.obj} (or updateEv) and assert got.Create(createEv) (or got.Update(updateEv)) equals tc.want.match, failing the test with the same cmp.Diff-based message if it does not match.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/reconciler/customresourcesgate/reconciler_test.go`:
- Around line 567-647: Add an extra assertion in TestGroupPredicate to exercise
at least one non-Generic event (e.g., Create or Update) so the predicate
behavior across event types is documented; locate the GroupPredicate(...) call
and the existing ev := event.GenericEvent{Object: tc.args.obj} and add a
corresponding createEv := event.CreateEvent{Object: tc.args.obj} (or updateEv)
and assert got.Create(createEv) (or got.Update(updateEv)) equals tc.want.match,
failing the test with the same cmp.Diff-based message if it does not match.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
pkg/controller/options.gopkg/reconciler/customresourcesgate/reconciler_test.gopkg/reconciler/customresourcesgate/setup.go
b356036 to
e54f430
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/reconciler/customresourcesgate/reconciler_test.go (1)
567-647: Test the predicate across all event types (Create, Update, Delete, Generic) to ensure consistent filtering behavior.The
GroupPredicateimplementation usespredicate.NewPredicateFuncs(), which applies the same filtering logic to all event types during watch operations. Currently, the test covers onlyGenericEvent. Consider adding equivalent test cases forCreate,Update, andDeleteevents—this will pin down behavior across all code paths the predicate actually handles in the controller.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/reconciler/customresourcesgate/reconciler_test.go` around lines 567 - 647, Extend TestGroupPredicate to exercise GroupPredicate across all event types: for each case call the predicate's Create, Update, Delete and Generic handlers (use event.CreateEvent, event.UpdateEvent, event.DeleteEvent, event.GenericEvent) with appropriate Objects (for UpdateEvent provide OldObject and Object) and assert the boolean result equals tc.want.match; locate the test loop in TestGroupPredicate and duplicate the current GenericEvent check into checks for got.Create, got.Update, and got.Delete so the predicate behavior is verified for all event paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/reconciler/customresourcesgate/reconciler_test.go`:
- Around line 567-647: Extend TestGroupPredicate to exercise GroupPredicate
across all event types: for each case call the predicate's Create, Update,
Delete and Generic handlers (use event.CreateEvent, event.UpdateEvent,
event.DeleteEvent, event.GenericEvent) with appropriate Objects (for UpdateEvent
provide OldObject and Object) and assert the boolean result equals
tc.want.match; locate the test loop in TestGroupPredicate and duplicate the
current GenericEvent check into checks for got.Create, got.Update, and
got.Delete so the predicate behavior is verified for all event paths.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
pkg/controller/options.gopkg/reconciler/customresourcesgate/reconciler_test.gopkg/reconciler/customresourcesgate/setup.go
🚧 Files skipped from review as they are similar to previous changes (2)
- pkg/controller/options.go
- pkg/reconciler/customresourcesgate/setup.go
Description of your changes
Fixes #910
What this fix does?
The
customresourcesgatereconciler was watching all CRDs cluster-wide with no filtering. This caused unnecessary reconcile cycles whenever any CRD event occurred — including CRDs from unrelated providers like cert-manager, flux, or other Crossplane providers installed in the same cluster.Fix
Adds a
Groups []stringfield to controller.Options. When set, the CRD gate controller applies a predicate that filters watch events to only CRDs belonging to the specified API groups.Note
Provider authors need to populate Groups in their main.go. upjet-based providers can be fixed upstream in code generation in a follow-up PR.
Docs tracking issue: 1067
I have:
./nix.sh flake checkto ensure this PR is ready for review.Addedbackport release-x.ylabels to auto-backport this PR.Need help with this checklist? See the cheat sheet.